/*     */ package nc.bs.mmpac.wr.bp;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import nc.bs.framework.common.NCLocator;
/*     */ import nc.itf.mmpac.wr.IWrMaintainService;
/*     */ import nc.itf.mmpac.wr.IWrTranstypeQueryService;
/*     */ import nc.util.mmf.framework.base.MMArrayUtil;
/*     */ import nc.util.mmf.framework.base.MMValueCheck;
/*     */ import nc.vo.mmpac.wr.entity.AggWrVO;
/*     */ import nc.vo.mmpac.wr.entity.WrItemVO;
/*     */ import nc.vo.mmpac.wr.enumeration.WrBillStatusEnum;
/*     */ import nc.vo.mmpub.util.MMPubCollectionUtils;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pub.CircularlyAccessibleValueObject;
/*     */ import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/*     */ import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
/*     */ import nc.vo.pubapp.pattern.model.transfer.bill.ClientBillCombinServer;
/*     */ import nc.vo.scmpub.util.CollectionUtils;
/*     */ import nccloud.pubitf.mmpub.commit.service.IBatchRunScriptService;
/*     */ import nccloud.pubitf.riart.pflow.CloudPFlowContext;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class WrSaveCommitBP
/*     */ {
/*     */   public AggWrVO[] updateCommit(AggWrVO[] vos) {
/*  36 */     if (MMArrayUtil.isEmpty(vos)) {
/*  37 */       return vos;
/*     */     }
/*  39 */     AggWrVO[] clientvos = (AggWrVO[])vos.clone();
/*     */     try {
/*  41 */       AggWrVO[] returnvos = getMainServ().update(clientvos);
/*  42 */       handleVO(vos, returnvos);
/*  43 */       commit(vos, returnvos);
/*  44 */     } catch (BusinessException e) {
/*  45 */       ExceptionUtils.wrappException(e);
/*     */     } 
/*  47 */     return vos;
/*     */   }
/*     */   
/*     */   public AggWrVO[] insertCommit(AggWrVO[] vos) {
/*  51 */     if (MMArrayUtil.isEmpty(vos)) {
/*  52 */       return vos;
/*     */     }
/*  54 */     AggWrVO[] clientvos = (AggWrVO[])vos.clone();
/*     */     try {
/*  56 */       AggWrVO[] returnvos = getMainServ().insert(clientvos);
/*  57 */       handleVO(vos, returnvos);
/*  58 */       commit(vos, returnvos);
/*  59 */     } catch (BusinessException e) {
/*  60 */       ExceptionUtils.wrappException(e);
/*     */     } 
/*  62 */     return vos;
/*     */   }
/*     */ 
/*     */   
/*     */   private AggWrVO[] commit(AggWrVO[] orginvos, AggWrVO[] vos) throws BusinessException {
/*  67 */     boolean isSaveAndAudit = false;
/*  68 */     AggWrVO vo = vos[0];
/*  69 */     if (MMValueCheck.isNotEmpty(vo.getParentVO().getVtrantypeid())) {
/*  70 */       isSaveAndAudit = isTransSaveAndApproved(vo);
/*  71 */       if (isSaveAndAudit) {
/*  72 */         approve(orginvos, vos);
/*     */         
/*  74 */         AggWrVO[] returns = (new WrAutoFlushForNccBP()).autoFlush(orginvos);
/*  75 */         handleVO(orginvos, returns);
/*     */       } else {
/*     */         
/*  78 */         CloudPFlowContext contextCommit = new CloudPFlowContext();
/*  79 */         contextCommit.setBillType("55A4");
/*  80 */         contextCommit.setActionName("SAVE");
/*  81 */         contextCommit.setBillVos(orginvos);
/*  82 */         Object[] objs = ((IBatchRunScriptService)NCLocator.getInstance().lookup(IBatchRunScriptService.class)).run(contextCommit, AggWrVO.class);
/*     */ 
/*     */         
/*  85 */         AbstractBill[] bills = (AbstractBill[])objs;
/*  86 */         AggWrVO[] returns = (AggWrVO[])MMPubCollectionUtils.convertArrayType(bills);
/*  87 */         handleVO(orginvos, returns);
/*     */       } 
/*     */     } 
/*  90 */     return vos;
/*     */   }
/*     */   
/*     */   private void approve(AggWrVO[] originvos, AggWrVO[] addreturnvos) throws BusinessException {
/*  94 */     List<String> tranids = new ArrayList<String>();
/*  95 */     for (AggWrVO aggWrVO : addreturnvos) {
/*  96 */       AggWrVO aggVO = (AggWrVO)aggWrVO;
/*  97 */       if (aggVO.getParentVO().getVtrantypeid() != null) {
/*  98 */         tranids.add(aggVO.getParentVO().getVtrantypeid());
/*     */       }
/*     */     } 
/* 101 */     IWrTranstypeQueryService transTypeService = (IWrTranstypeQueryService)NCLocator.getInstance().lookup(IWrTranstypeQueryService.class);
/* 102 */     Map<String, Boolean> isSaveApproves = transTypeService.isSaveToAuditTransType((String[])tranids.toArray(new String[0]));
/* 103 */     List<AggWrVO> hasApproves = new ArrayList<AggWrVO>();
/* 104 */     for (AggWrVO aggWrVO : addreturnvos) {
/* 105 */       AggWrVO aggVO = (AggWrVO)aggWrVO;
/* 106 */       if (WrBillStatusEnum.FREEDOM.equalsValue(aggVO.getParentVO().getFbillstatus()) && 
/* 107 */         isSaveApproves.get(aggVO.getParentVO().getVtrantypeid()) != null && ((Boolean)isSaveApproves
/* 108 */         .get(aggVO.getParentVO().getVtrantypeid())).booleanValue()) {
/* 109 */         hasApproves.add(aggVO);
/*     */       }
/*     */     } 
/*     */     
/* 113 */     if (hasApproves.size() > 0) {
/* 114 */       AggWrVO[] vos = (AggWrVO[])hasApproves.toArray(new AggWrVO[hasApproves.size()]);
/* 115 */       for (AggWrVO vo : vos) {
/* 116 */         vo.getParentVO().setFbillstatus(Integer.valueOf(WrBillStatusEnum.COMMITE.toIntValue()));
/*     */       }
/* 118 */       AggWrVO[] returns = getMainServ().audit(vos);
/* 119 */       handleVO(originvos, returns);
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   private boolean isTransSaveAndApproved(AggWrVO vo) throws BusinessException {
/* 125 */     if (MMValueCheck.isEmpty(vo) || MMValueCheck.isEmpty(vo.getParentVO())) {
/* 126 */       return false;
/*     */     }
/*     */     
/* 129 */     if (vo.getParentVO().getVtrantypeid() == null) {
/* 130 */       return false;
/*     */     }
/* 132 */     IWrTranstypeQueryService transTypeService = (IWrTranstypeQueryService)NCLocator.getInstance().lookup(IWrTranstypeQueryService.class);
/*     */     
/* 134 */     Map<String, Boolean> isSaveApproves = transTypeService.isSaveToAuditTransType(new String[] { vo.getParentVO().getVtrantypeid() });
/*     */     
/* 136 */     Boolean ret = (Boolean)isSaveApproves.get(vo.getParentVO().getVtrantypeid());
/* 137 */     if (ret != null) {
/* 138 */       return ret.booleanValue();
/*     */     }
/*     */     
/* 141 */     return false;
/*     */   }
/*     */ 
/*     */   
/* 145 */   private static IWrMaintainService getMainServ() { return (IWrMaintainService)NCLocator.getInstance().lookup(IWrMaintainService.class); }
/*     */ 
/*     */   
/*     */   private AggWrVO[] handleVO(AggWrVO[] originvos, AggWrVO[] returnvos) throws BusinessException {
/* 149 */     List<CircularlyAccessibleValueObject> circularList = new ArrayList<CircularlyAccessibleValueObject>();
/* 150 */     WrItemVO[] arrayOfWrItemVO = originvos[0].getChildrenVO();
/* 151 */     for (WrItemVO wrItemVO : arrayOfWrItemVO) {
/* 152 */       if (wrItemVO.getStatus() != 3) {
/* 153 */         circularList.add(wrItemVO);
/*     */       }
/*     */     } 
/* 156 */     originvos[0].setChildrenVO((CircularlyAccessibleValueObject[])CollectionUtils.listToArray(circularList));
/* 157 */     ClientBillCombinServer<AggWrVO> combinServer = new ClientBillCombinServer<AggWrVO>();
/* 158 */     combinServer.combine(originvos, returnvos);
/* 159 */     return originvos;
/*     */   }
/*     */ }


/* Location:              E:\zhuhai_ncc\NCC2111\modules\mmpac\META-INF\lib\mmpac_wr.jar!/nc/bs/mmpac/wr/bp/WrSaveCommitBP.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */